<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Flow: flow::util::String_ostream Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">Flow<span id="projectnumber">&#160;2.0.0</span>
   </div>
   <div id="projectbrief">Flow project: Public API.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespaceflow.html">flow</a></li><li class="navelem"><a class="el" href="namespaceflow_1_1util.html">util</a></li><li class="navelem"><a class="el" href="classflow_1_1util_1_1String__ostream.html">String_ostream</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classflow_1_1util_1_1String__ostream-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">flow::util::String_ostream Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Similar to <code>ostringstream</code> but allows fast read-only access directly into the <code>std::string</code> being written; and some limited write access to that string.  
 <a href="classflow_1_1util_1_1String__ostream.html#details">More...</a></p>

<p><code>#include &lt;string_ostream.hpp&gt;</code></p>

<p>Inherits boost::noncopyable.</p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a555fa9e2f764b9599fa7027f9d3a0051"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1util_1_1String__ostream.html#a555fa9e2f764b9599fa7027f9d3a0051">String_ostream</a> (std::string *target_str=0)</td></tr>
<tr class="memdesc:a555fa9e2f764b9599fa7027f9d3a0051"><td class="mdescLeft">&#160;</td><td class="mdescRight">Wraps either the given <code>std::string</code> or a newly created empty string if a null pointer is passed.  <a href="classflow_1_1util_1_1String__ostream.html#a555fa9e2f764b9599fa7027f9d3a0051">More...</a><br /></td></tr>
<tr class="separator:a555fa9e2f764b9599fa7027f9d3a0051"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7e64b069ae0e221952068c13fdc0f080"><td class="memItemLeft" align="right" valign="top">std::ostream &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1util_1_1String__ostream.html#a7e64b069ae0e221952068c13fdc0f080">os</a> ()</td></tr>
<tr class="memdesc:a7e64b069ae0e221952068c13fdc0f080"><td class="mdescLeft">&#160;</td><td class="mdescRight">Access to stream that will write to owned string.  <a href="classflow_1_1util_1_1String__ostream.html#a7e64b069ae0e221952068c13fdc0f080">More...</a><br /></td></tr>
<tr class="separator:a7e64b069ae0e221952068c13fdc0f080"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa727e60e370a7fab3148f5bf8c31ad99"><td class="memItemLeft" align="right" valign="top">const std::ostream &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1util_1_1String__ostream.html#aa727e60e370a7fab3148f5bf8c31ad99">os</a> () const</td></tr>
<tr class="memdesc:aa727e60e370a7fab3148f5bf8c31ad99"><td class="mdescLeft">&#160;</td><td class="mdescRight">Read-only access to stream that will write to owned string.  <a href="classflow_1_1util_1_1String__ostream.html#aa727e60e370a7fab3148f5bf8c31ad99">More...</a><br /></td></tr>
<tr class="separator:aa727e60e370a7fab3148f5bf8c31ad99"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa7682e71a5e96955a52643e63bf97ad0"><td class="memItemLeft" align="right" valign="top">const std::string &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1util_1_1String__ostream.html#aa7682e71a5e96955a52643e63bf97ad0">str</a> () const</td></tr>
<tr class="memdesc:aa7682e71a5e96955a52643e63bf97ad0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Read-only access to the string being wrapped.  <a href="classflow_1_1util_1_1String__ostream.html#aa7682e71a5e96955a52643e63bf97ad0">More...</a><br /></td></tr>
<tr class="separator:aa7682e71a5e96955a52643e63bf97ad0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a55008c2e651cfc832182a941284f7e7e"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1util_1_1String__ostream.html#a55008c2e651cfc832182a941284f7e7e">str_clear</a> ()</td></tr>
<tr class="memdesc:a55008c2e651cfc832182a941284f7e7e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs <code>std::string::clear()</code> on the object returned by <code><a class="el" href="classflow_1_1util_1_1String__ostream.html#aa7682e71a5e96955a52643e63bf97ad0" title="Read-only access to the string being wrapped.">str()</a></code>.  <a href="classflow_1_1util_1_1String__ostream.html#a55008c2e651cfc832182a941284f7e7e">More...</a><br /></td></tr>
<tr class="separator:a55008c2e651cfc832182a941284f7e7e"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Similar to <code>ostringstream</code> but allows fast read-only access directly into the <code>std::string</code> being written; and some limited write access to that string. </p>
<p >Also it can take over an existing <code>std::string</code>.</p>
<p ><code>ostringstream</code> is fine, except for the giant flaw that is the fact that the essentially only way to read the string is to call <code>ostringstream::str()</code> which returns a copy, not a reference.</p>
<dl class="todo"><dt><b><a class="el" href="todo.html#_todo000072">Todo:</a></b></dt><dd>Consider using <code>alt_sstream</code> in boost.format; it doesn't seem to have public documentation but isn't in a <code>detail</code> directory either. So that's interesting. It might have better performance than the implementation here (by being more "direct" probably). Then again it might not.</dd></dl>
<h3>Thread safety</h3>
<p >This provides the same level of thread safety as <code>ostringstream</code>. That is, you should use a mutex if planning concurrent read/write access to the same object. </p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a555fa9e2f764b9599fa7027f9d3a0051" name="a555fa9e2f764b9599fa7027f9d3a0051"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a555fa9e2f764b9599fa7027f9d3a0051">&#9670;&nbsp;</a></span>String_ostream()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">flow::util::String_ostream::String_ostream </td>
          <td>(</td>
          <td class="paramtype">std::string *&#160;</td>
          <td class="paramname"><em>target_str</em> = <code>0</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">explicit</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Wraps either the given <code>std::string</code> or a newly created empty string if a null pointer is passed. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">target_str</td><td>Pointer to the string of which to take ownership; null to use an internal string currently blank. If non-null is passed, any subsequnt access to <code>*target_str</code> except via this class's API results in undefined behavior. (It should go without saying, but using <code>const_cast</code> or equivalents counts as being outside the bounds of this class's API.) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a7e64b069ae0e221952068c13fdc0f080" name="a7e64b069ae0e221952068c13fdc0f080"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7e64b069ae0e221952068c13fdc0f080">&#9670;&nbsp;</a></span>os() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::ostream &amp; flow::util::String_ostream::os </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Access to stream that will write to owned string. </p>
<dl class="section return"><dt>Returns</dt><dd>Stream. </dd></dl>

</div>
</div>
<a id="aa727e60e370a7fab3148f5bf8c31ad99" name="aa727e60e370a7fab3148f5bf8c31ad99"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa727e60e370a7fab3148f5bf8c31ad99">&#9670;&nbsp;</a></span>os() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">const std::ostream &amp; flow::util::String_ostream::os </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Read-only access to stream that will write to owned string. </p>
<dl class="section return"><dt>Returns</dt><dd>Read-only reference to stream. </dd></dl>

</div>
</div>
<a id="aa7682e71a5e96955a52643e63bf97ad0" name="aa7682e71a5e96955a52643e63bf97ad0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa7682e71a5e96955a52643e63bf97ad0">&#9670;&nbsp;</a></span>str()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">const std::string &amp; flow::util::String_ostream::str </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Read-only access to the string being wrapped. </p>
<p >The reference's value never changes for <code>*this</code> object. The string's value may change, if one writes to <code><a class="el" href="classflow_1_1util_1_1String__ostream.html#a7e64b069ae0e221952068c13fdc0f080" title="Access to stream that will write to owned string.">os()</a></code> or does <a class="el" href="classflow_1_1util_1_1String__ostream.html#a55008c2e651cfc832182a941284f7e7e" title="Performs std::string::clear() on the object returned by str().">str_clear()</a>, etc.</p>
<h3>Rationale</h3>
<p >Why return <code>const string&amp;</code> instead of <a class="el" href="namespaceflow_1_1util.html#ae4dc52186797094b3040379ff19124c9" title="Commonly used char-based Basic_string_view. See its doc header.">util::String_view</a>? Answer: By definition we are backed by an <code>std::string</code>, either our own or one user actively passed to ctor. Hence it's unnecessary obfuscation; plus it can lead to errors, like if the user thinks a returned object's <code>String_view::size()</code> will auto-adjust based on what happens to the wrapped <code>std::string</code> subsequently. If they want a <code>String_view</code>, they can always just construct one, just as we would inside here anyway.</p>
<dl class="section return"><dt>Returns</dt><dd>Read-only reference to string; the address therein is guaranteed to always be the same given a <code>*this</code>. </dd></dl>

</div>
</div>
<a id="a55008c2e651cfc832182a941284f7e7e" name="a55008c2e651cfc832182a941284f7e7e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a55008c2e651cfc832182a941284f7e7e">&#9670;&nbsp;</a></span>str_clear()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void flow::util::String_ostream::str_clear </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Performs <code>std::string::clear()</code> on the object returned by <code><a class="el" href="classflow_1_1util_1_1String__ostream.html#aa7682e71a5e96955a52643e63bf97ad0" title="Read-only access to the string being wrapped.">str()</a></code>. </p>
<p >The latter is <code>const</code>, so you may not call <code>clear()</code> directly.</p>
<dl class="section note"><dt>Note</dt><dd><code>clear()</code> is a frequently desired operation, which is why access to it is provided as a special case. It is intentional that no read-write version of <a class="el" href="classflow_1_1util_1_1String__ostream.html#aa7682e71a5e96955a52643e63bf97ad0" title="Read-only access to the string being wrapped.">str()</a> is provided for arbitrary write operations. </dd></dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>util/<a class="el" href="string__ostream_8hpp.html">string_ostream.hpp</a></li>
<li>util/<a class="el" href="string__ostream_8cpp.html">string_ostream.cpp</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Mar 28 2025 22:55:32 for Flow by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
